package com.example.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.example.demo.enity.Msg;
import com.example.demo.service.AdminService;
import com.example.demo.service.UserService;
/**
 * 管理员控制器
 * @author acer
 *
 */
@Controller
public class AdminController {

	@Autowired
	AdminService adminService;
	@Autowired
	UserService userService;
	/**
	 * 
	 * 返回管理员页面
	 * @return
	 */
	@RequestMapping("/admin/adminpage")
	  public String adminpage() {
		  return "adminpage";
	  }
	
	
	/**
	 * 查询所有违规次数大于 5次的用户
	 * @return
	 */
	@RequestMapping(value="/admin/selectAllIlleageUser",method = RequestMethod.POST)
	@ResponseBody
	  public Msg selectAllIlleageUser() {
		
		if(adminService.selectAllIlleageUser().isEmpty()) {
			return Msg.fail();
		}else {
			return Msg.success().add("illeageuserinfos", adminService.selectAllIlleageUser());
		}
			
			
		
	  }
	
	/**
	 * 封号
	 */
	@RequestMapping(value="/admin/bannedUser",method = RequestMethod.POST)
	@ResponseBody
	public Msg bannedUser(Integer uid) {
		return Msg.success().add("bannedUser", adminService.bannedUser(uid));
	}
	
	/**
	 * 查询所有违规次数大于 3次的招聘
	 * @return
	 */
	@RequestMapping(value="/admin/selectAllIlleageRecuitment",method = RequestMethod.POST)
	@ResponseBody
	  public Msg selectAllIlleageRecuitment() {
		if(adminService.selectAllIlleageRecuitment().isEmpty()) {
			return Msg.fail();
		}else {
			return Msg.success().add("illeageRecuitment", adminService.selectAllIlleageRecuitment());	
		}
	  }
	/**
	 * 根据就招聘id删除招聘
	 */
	@RequestMapping(value="/admin/deleteRecruitmentByPrimaryKey",method = RequestMethod.POST)
	@ResponseBody
	public Msg deleteRecruitmentByPrimaryKey(Integer zpid) {
		return Msg.success().add("deleteRecruitmentByPrimaryKey", adminService.deleteByPrimaryKey(zpid));
	}
}
